<?
	include_once 'functionsDocs_06082009.php';
	include 'headermenu.php';


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html>
<!-- <link rel="stylesheet" type="text/css" href="default.css"> -->
<!--
-->
<link rel="stylesheet" href="yui.css" type="text/css">
<head>
	<title>Methodology Portal</title>
</head>

<body>
<div id="doc" class="yui-t7">
  
   <div id="bd" role="main">
 
 
 <div class="yui-gc">
    <div class="yui-u first">
	<!-- YOUR DATA GOES HERE -->
    <form action="" name="testQR" method="post" >
	<div align="right">  <input type="submit" name="add" value="Adauga" align="right"> </div>
	</form>
	    </div>
    <div class="yui-u">
	<!-- YOUR DATA GOES HERE -->
	    </div>
 </div>



 <div class="yui-gc">
    <div class="yui-u first" >
 <!-- PRIMUL ECRAN!!! -->
 
<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
	mode : "textareas",
	theme : "simple"
});
</script>



	
	<?
	//Conectare la DB:
	$dbh=dbConn();
	
	//####MODIFICA SECTIUNE:
	if(isset($_POST['qr_update']))
	{
	$resulte = returnQuery("update document_body set content='".$_POST["content"]."' where id=".$_GET["rowid"].";", $dbh);
	unset($_GET["rowid"]);
	}
	

	//####ADAUGA SECTIUNE:
	if(isset($_POST['qr_add']))
	{
		//echo ("A fost adaugat un nou proiect.");
		//select from 
		echo $_POST['sel_place'];
		
		//mysql_query("insert into document_body (id, id_project, id_stage, id_substage, id_doc, content, parent, order_line, type)
		//values (null, 1, 1, 1, 1, 'WRITE THE NEW TITLE HERE!!!', 0, 'XXX', 'Title')") or die(mysql_error());


		//mysql_query("INSERT INTO projects(id, name, description, start_date, stop_date, time, user, edit_date) 
		//VALUES(null, '".$_POST['name']."', '".$_POST['description']."', now(), now(), '".$_POST['time']."', '".$_POST['user']."', now()); ") 		or die(mysql_error());  
		//unset($_GET[rowid]);
		//refreshPage('http://localhost/methodology/');
	}


	
	//Afiseaza body-ul documentului:
	$result = returnQuery("select * from document_body order by order_line asc;", $dbh);
	echo '<table width=100%><form action="" name="testQR" method="post">';
	echo '<tr><td>Meniu</td><td>Document</td></tr>';

	
	while ($row = mysql_fetch_assoc($result)) {
		echo "<tr><td><a href='documents.php?rowid=".$row["id"]."'>edit</a></td><p>";
		if ($row["type"]=="Content") {
			if ($_GET["rowid"] == $row["id"]) {
				?><td><textarea name="content" rows="30" style='width:100%'><? echo $row["content"]; ?> </textarea>
				<input type="submit" name="qr_update" value="Update" ></input></td> <?
			} else {
				
				?><td><div class="yui-test"><? echo stripslashes($row["content"]); ?> </div></td><?
				
			}
			
		} else {
			if ($_GET["rowid"] == $row["id"]) {
				?> <td><input name="content" type="text" value=" <? echo $row["content"]; ?>" style='width:100%'></input>
				<br><input type="submit" name="qr_update" value="Update" ></input></td> <?
			} else {
				echo "<td>".$row["content"]."</td>";
			}
		}
		
		echo "</p></tr>";
	}
	echo "</form></table>";
	mysql_free_result($result);	
	?>

    </div>
<div class="yui-u">
 <!-- AL DOILEA ECRAN!!! -->

	<?
	//####afisam sectiunea add/update/delete:
	if(isset($_POST['add'])) 
	{
		unset($_GET[rowid]);
		display($_GET[0]);
	}




	?>
 <br>
     </div>
</div>
 
	<?
	dbClose($dbh);
	?>

 </div>
  
</div>
</body>
</html>
<? include 'footer.php';
?>